package com.hnl.action.user;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.core.HNLPageDispatch;

@SuppressWarnings("serial")
public class UserLogout extends HttpServlet implements HNLPageDispatch {
	public static final Logger LOG = LoggerFactory.getLogger(UserLogout.class);

	private final String LOGOUT_MESSAGE = "You have successfully logged out.";

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		RequestDispatcher dispatcher = req.getRequestDispatcher(LOGIN_PAGE);

		HttpSession session = req.getSession();
		session.invalidate();

		dispatcher = req.getRequestDispatcher(LOGIN_PAGE);
		req.setAttribute("error", LOGOUT_MESSAGE);

		dispatcher.forward(req, resp);
	}
}
